#include "tests/unit/unit_test.hpp"
#include <memory>
#include <string>

void test_function_lambda()
{
    std::unique_ptr<std::string> str_ptr = std::unique_ptr<std::string>(new std::string("233"));
    auto func = [s = std::move(str_ptr)]() {
        std::cout << *s << '\n';
    };
    func();
}

class A
{
public:
    virtual void operator()()
    {
        std::cout << "A()" << '\n';
    }
};

class B : public A
{
public:
    virtual void operator()() override
    {
        std::cout << "B()" << '\n';
    }
};

int ask() { return 42; }
typedef decltype(ask)* function_ptr;

class convertible_to_function_ptr
{
public:
    operator function_ptr() const
    {
        return ask;
    }
};



void test_function_operator()
{
    A* a = new A();
    (*a)();

    A* a2 = new B();
    (*a2)();

    B* b = new B();
    (*b)();
}

void test_function_wrapper()
{
    convertible_to_function_ptr ask_wrapper;
    std::cout << ask_wrapper() << '\n';
}

int main()
{
    TEST_CASE(test_function_wrapper);
    TEST_CASE(test_function_operator);
    TEST_CASE(test_function_lambda);
    return 0;
}